package com.leapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SelecaoActivity extends Activity {
	Usuario usuario;
	TextView aux; //serve para escrever os textos na lista de  questionarios
	ArrayAdapter adapter; //adiciona itens na listView
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_selecao);
		usuario = Usuario.getInstancia();
		
		TextView bemVindo = (TextView) findViewById(R.id.bem_vindo);
		ListView questionariosList = (ListView) findViewById(R.id.questionarios_list);
		bemVindo.setText("Olá "+usuario.getUsername()+"!");

		//Preparando lista de questionarios
		adapter= new ArrayAdapter<String>(questionariosList.getContext(),R.layout.item_lista_questionario,usuario.getQuestionarios());
		questionariosList.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				TextView selecionada = (TextView) arg1;
				//Ao clicar, inicie o questionario
				Questionario questionario = Questionario.getInstancia();
				questionario.init(selecionada.getText().toString());
				
				//Mostre a primeira pergunta
				Bundle bundle = questionario.getBundleQuestao(0);
				Intent selecao_questao;
				switch(bundle.getInt("com.leapp.tipo")){
				case(Definicoes.QUESTAO_SIMPLES):
					selecao_questao = new Intent(getBaseContext(),QuestaoSimplesActivity.class);
					selecao_questao.putExtras(bundle);
					startActivity(selecao_questao);
					break;
				};
			}
			
		});
		
		questionariosList.setAdapter(adapter);

		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.selecao, menu);
		return true;
	}

}
